//
//  GC_GoodsTypesInfoCollectionViewCell.m
//  WisdomConsumption
//
//  Created by mini3 on 2017/9/15.
//  Copyright © 2017年 WisdomConsumption. All rights reserved.
//

#import "GC_GoodsTypesInfoCollectionViewCell.h"

@interface GC_GoodsTypesInfoCollectionViewCell ()

///背景
@property (nonatomic, weak) UIImageView *bgImageView;
///左线
@property (nonatomic, weak) UIImageView *leftLineImageView;
///下划线
@property (nonatomic, weak) UIImageView *bottomLineImageView;
///标题
@property (nonatomic, weak) UILabel *titleLabel;


@end

@implementation GC_GoodsTypesInfoCollectionViewCell

///注册cell
+(void)registerCollectionView:(UICollectionView*)collectionView
{
    [collectionView registerClass:[GC_GoodsTypesInfoCollectionViewCell class] forCellWithReuseIdentifier:@"GC_GoodsTypesInfoCollectionViewCell"];
}

///创建
+(id)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [collectionView dequeueReusableCellWithReuseIdentifier:@"GC_GoodsTypesInfoCollectionViewCell" forIndexPath:indexPath];
}

///初始化
-(void)initDefault
{
    
}

///加载子视图约束
-(void)loadSubviewConstraints
{
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    
    [self.leftLineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView);
        make.width.mas_equalTo(WIDTH_TRANSFORMATION(3));
    }];
    
    [self.bottomLineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView);
    }];
    
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(WIDTH_TRANSFORMATION(12));
        make.right.equalTo(self.contentView).offset(WIDTH_TRANSFORMATION(-12));
        make.centerY.equalTo(self.contentView);
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

#pragma mark -- private
///更新
- (void)updateUiForData:(NSString *)nameStr
{
    self.titleLabel.text = nameStr;
}
- (void)updateUiForDatas:(NSMutableDictionary *)data{
    if (data) {
        self.titleLabel.text = data[@"cate_name"];
    }
}
///设置选中状态
- (void)setSelectedState:(BOOL)selected
{
    if(selected){
        self.titleLabel.textColor = kFontColorRed;
        self.leftLineImageView.hidden = NO;
        [self.bgImageView setImageForName:@"shop_classification_bottom1"];
    }else{
        self.titleLabel.textColor = kFontColorBlack;
        self.leftLineImageView.hidden = YES;
        [self.bgImageView setImageForName:@"shop_classification_bottom"];
    }
}



#pragma mark -- getter,setter

///背景
- (UIImageView *)bgImageView
{
    if(!_bgImageView){
        UIImageView *image = [UIImageView createImageViewWithName:@"shop_classification_bottom"];
        [self.contentView addSubview:_bgImageView = image];
    }
    return _bgImageView;
}

///左线
- (UIImageView *)leftLineImageView
{
    if(!_leftLineImageView){
        UIImageView *image = [UIImageView createImageViewWithName:@"public_selected3"];
//        image.backgroundColor = kCommonBlueBgColor;
        image.hidden = YES;
        [self.contentView addSubview:_leftLineImageView = image];
    }
    return _leftLineImageView;
}

///下划线
- (UIImageView *)bottomLineImageView
{
    if(!_bottomLineImageView){
        UIImageView *image = [UIImageView createImageViewWithName:@"business_details_list_line_long"];
        [self.contentView addSubview:_bottomLineImageView = image];
    }
    return _bottomLineImageView;
}


///标题
- (UILabel *)titleLabel
{
    if(!_titleLabel){
        UILabel *label = [UILabel createLabelWithText:@"水果蔬菜" font:kFontSize_26];
        [label setTextAlignment:NSTextAlignmentCenter];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
@end
